1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : news/classes/class.NewsCategoryRessources.inc.php
5 : - Modulgruppe: News
6 : - Beschreibung: Klasse für die News-Kategorie Ressourcen.
7 : - Version: 1.1.2.4, 24/01/08
8 : - Autor(en): Corinna Kropf <corinna.kropf@mni.fh-giessen.de>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 :
24 1 : require_once ("class.newscategory.inc.php");
25 :
26 : /**
27 : * Klasse für die News-Kategorie Ressources.
28 : * @package eStudy.News
29 : * @version 1.1.2.4, 24/01/08
30 : * @author Corinna Kropf <corinna.kropf@mni.fh-giessen.de>
31 : */
32 1 : class NewsCategoryRessources extends NewsCategory
33 : {
34 : /**
35 : * Cache Objekt zur Abfrage von Modulinstallationen (Performance Tweak)
36 : * @var array
37 : */
38 : private $installCacheObject;
39 : /**
40 : * Flag fuer die Anzeige der News-Eintraege
41 : * @var bool
42 : */
43 : private $dark;
44 : /**
45 : * HTML-Template
46 : * @var Template
47 : */
48 : private $newsTemplate;
49 : /**
50 : * @var int
51 : */
52 : private $userID;
53 : /**
54 : * Konstruktor
55 : */
56 : public function __construct($catID, $courses, $userID, $categorySettings = null, $cacheObject = null)
57 : {
58 0 : parent::__construct($catID, $courses, $categorySettings);
59 0 : $this->installCacheObject = $cacheObject;
60 0 : $this->userID = $userID;
61 0 : $this->newsTemplate = new Template(PATH_TO_ROOT."news/templates/newsressources.html");
62 0 : }
63 : /**
64 : * Überschreibt die Methode der Oberklasse,
65 : * um weitere Initialisierungen vor der Ausgabe zu machen.
66 : * @see NewsCategory
67 : */
68 : public function echoNews($courseID, $usergroup = null)
69 : {
70 0 : $this->dark = false;
71 0 : parent::echoNews($courseID, $usergroup);
72 0 : }
73 : /**
74 : * Muss angepasst werden, falls Modulgruppen umbenannt werden!
75 : * @see NewsCategory
76 : */
77 : public function isInstalled($courseID)
78 : {
79 0 : return Utilities::isInstalled("resources", $courseID, $this->installCacheObject);
80 : }
81 : /**
82 : * @see NewsCategory
83 : */
84 : public function canSelectPeriod() {
85 0 : return true;
86 : }
87 : /**
88 : * @see NewsCategory
89 : */
90 : public function getNewsHeaderTitle($courseID = null, $type = null) {
91 0 : if(isset($this->news))
92 0 : {
93 0 : $newsCount = $this->news["count"];
94 0 : if ($newsCount > 1) $title = sprintf( $this->translate->_("%1\$s Ressourcen"), $newsCount);
95 0 : elseif ($newsCount == 1) $title = $this->translate->_("1 Ressource");
96 0 : }
97 0 : else $title = $this->translate->_("Keine neuen Ressourcen");
98 :
99 0 : return $title;
100 : }
101 :
102 : /**
103 : * @see NewsCategory
104 : */
105 : protected function getNewsByPeriod($courseID, $from, $to, $lastvisit, $usergroup = null) {
106 : // Neue Mitteilungen
107 0 : if (isset($courseID) && isset($from) && isset($to) && isset($this->coursePreferences))
108 0 : {
109 0 : if(!is_numeric($courseID) || !is_numeric($from) || !is_numeric($to) || !is_numeric($usergroup)) return null;
110 :
111 0 : global $db;
112 0 : $this->news = array();
113 :
114 : switch ($usergroup) {
115 0 : case ADMIN:
116 0 : case DOZENT:
117 0 : $visible = " IN (1,2,3)";
118 0 : break;
119 :
120 0 : case STUDENT:
121 0 : case SCHUELER:
122 0 : case ALUMNUS:
123 0 : case GAST:
124 0 : $visible = "=1";
125 0 : break;
126 :
127 0 : case SEKRETARIAT:
128 0 : $visible = " IN (1,2)";
129 0 : }
130 :
131 : //$time = $this->getPeriod($courseID, $lastvisit);
132 0 : $timefrom = $this->getPeriod($courseID, $from);
133 0 : $timeto = $to;
134 :
135 : // Für Studenten und Hilfsadmins individuell freigegebene Dateien auslesen
136 0 : if ($usergroup == STUDENT || $usergroup == SEKRETARIAT) {
137 0 : $visible_for_user = $db->get_col("SELECT fileID FROM filevisible WHERE userID='$this->userID'");
138 0 : if ($db->num_rows) $visible_for_user = implode(",", $visible_for_user);
139 0 : }
140 : $sql = "SELECT * FROM filelist "
141 0 : ."WHERE (visible_type$visible".(!empty($visible_for_user) ? " OR fileID IN ($visible_for_user)" : "") .") "
142 0 : ."AND type IN ('file','link') "
143 0 : ."AND ((start_time>0 AND start_time>=$timefrom AND start_time<$timeto) "
144 0 : ."OR (start_time=0 AND create_time>=$timefrom)) "
145 0 : ."AND courseID='$courseID' "."ORDER BY create_time DESC";
146 0 : $this->news["data"] = $db->get_results($sql, ARRAY_A);
147 0 : if ($db->num_rows > 0) {
148 0 : $this->news["count"] = $db->num_rows;
149 : // Ressourcen entfernen, die in einem Ordner liegen,
150 : // der im Gegensatz zur Ressource nicht fuer den Nutzer sichtbar ist
151 : // und Hinzufügen der Pfadangaben zu den Ressourcendaten
152 0 : $count = count($this->news["data"]);
153 0 : for ($i = 0 ; $i < $count ; $i++) {
154 0 : $parent = $this->news["data"][$i]["parent_object"];
155 0 : $this->news["data"][$i]["path"] = " / ";
156 0 : while ($parent > 0) {
157 0 : $parent_data = $db->get_row("SELECT link, parent_object, visible_type FROM filelist WHERE fileID=$parent", ARRAY_A);
158 0 : if (($usergroup == STUDENT || $usergroup == SEKRETARIAT) && ($parent_data["visible_type"] > $this->news["data"][$i]["visible_type"])) {
159 0 : unset($this->news["data"][$i]);
160 0 : $this->news["count"]--;
161 0 : break;
162 : }
163 0 : $this->news["data"][$i]["path"] = " / ".$parent_data["link"].$this->news["data"][$i]["path"];
164 0 : $parent = $parent_data["parent_object"];
165 0 : $this->users[$this->news["data"][$i]["userID"]] = $this->news["data"][$i]["userID"];
166 0 : }
167 0 : }
168 0 : if($this->news["count"] == 0) $this->news = null;
169 0 : } else $this->news = null;
170 0 : }
171 :
172 0 : return $this->news;
173 : }
174 : /**
175 : * @see NewsCategory
176 : */
177 : protected function echoNewsEntry($entry, $courseID, $usergroup = null)
178 : {
179 0 : if(!isset($this->dark) || !isset($entry) || !isset($courseID) || !isset($this->news["user"])) return;
180 :
181 0 : $ressourcePath = PATH_TO_ROOT."ressourcen";
182 0 : $name = Data::toHTML($entry["name"], false);
183 0 : $entryPath = ((isset($entry["path"]))? Data::toHTML($entry["path"], false) : "");
184 0 : if($entry["type"] == "file") {
185 0 : $linkOption = $this->translate->_("Diese Datei herunterladen");
186 0 : $type = "file";
187 0 : $type_info = $this->translate->_("Datei");
188 0 : $fileSize = Data::toHTML(number_format($entry["size"]/1024, 1, ",", "."), false);
189 0 : $size = " <span style='font-style:italic;font-weight:normal'>(".$fileSize." KB)</span>";
190 0 : }
191 : else {
192 0 : $linkOption = $this->translate->_("Diese Seite öffnen");
193 0 : $type = "link";
194 0 : $type_info = $this->translate->_("Link");
195 0 : $size = "";
196 : }
197 :
198 : // Nur verlinken, wenn Datei noch angezeigt werden soll
199 0 : if ($entry["end_time"] > time()) {
200 : // aus dem Foyer in einen Kurs
201 0 : if ($courseID && $courseID != $_SESSION["course"]) $changeToCourse = "&changeToCourse=$courseID";
202 0 : else $changeToCourse = "";
203 0 : $folder = "activeFolder=$entry[parent_object]";
204 0 : $action="&action=get$entry[type]&actionID=$entry[fileID]$changeToCourse";
205 0 : $ressourceInfo = "<a href='$ressourcePath/filemanager.php?$folder$action' title='$linkOption'>$name</a>";
206 0 : }
207 : else $ressourceInfo = $name." <span style='font-style:italic;font-weight:normal'>("
208 0 : . $this->translate->_("Nicht mehr verfügbar.")
209 0 : . ")</span>";
210 0 : $userLink = $this->getProfileLink($this->news["user"], $entry["userID"], $courseID);
211 0 : if ($role = RoleArtefacts::getRoleForItem($this->myCategory, (int)$entry["fileID"])) {
212 0 : $userLink.= " (".$role->getPropertiesLink($role->getName($this->news["user"][$entry["userID"]]["gender"]), $this->translate->_("Rollen-Eigenschaften anzeigen"), true) .")";
213 0 : }
214 0 : if (!empty($entry["description"])) $description = Data::toHTML($this->bbcode->stripTags($entry["description"]));
215 0 : else $description = "";
216 0 : eval($this->newsTemplate->GetTemplate());
217 0 : }
218 : }
|